//
//  QUE_LESSOperationController.m
//  QUE_LESS
//
//  Created by Alex on 21/07/2011.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "QUE_LESSOperationController.h"

@implementation QUE_LESSOperationController
@synthesize queue,responseText;

-(id)initWithStartUpCommands:(NSString *)startupcommand{

    //start our app after launching with a new thread for network request
    if(!queue)
    {        
    queue =  dispatch_queue_create("com.QUE_LESS.mainQueue", NULL);
    }
    dispatch_async(queue, ^{

        
        networkController *startupRequest = [[networkController alloc] init];
        [startupRequest setDelegate:self];
        [startupRequest makeRequestForJSON:PLACEHOLDERURL];
        dispatch_sync(dispatch_get_main_queue(), ^{
          
            coreDataController *saveRequest = [[coreDataController alloc] init];
            [saveRequest setDelegate:self];
            //save into coreData
            [saveRequest saveJSONtoCoreData:responseText];
                        
            //retrieve
            NSLog(@"%@",[saveRequest retrieveJSONFromCoreData]);
            
            //delete
            //[saveRequest deleteJSONFromCoreData];
        });
    });
    return self;
}
-(void)requestNetworkUpdate:(NSString *)URL{
    
    dispatch_async(queue, ^{
        
        networkController *request = [[networkController alloc] init];
        [request setDelegate:self];
        [request makeUpdateRequest:URL];
    });
    
};
#pragma mark network delegate callback
-(void)networkControllerResponse:(id)responderJSON
{
    responseText = responderJSON;   
    

};
#pragma endregion
#pragma mark coredata selector reply
-(void)coreDataSaveStatus:(int)statusCode{
    
    NSLog(@"Core Data save status : %d",statusCode); 
    //perform an action on a particular code
}
-(void)coreDataRetrieveStatus:(int)statusCode{
    
    NSLog(@"Core Data retrieve status : %d",statusCode); 
    //perform an action on a particular code
}
-(void)coreDataDeleteStatus:(int)statusCode{
    NSLog(@"Core Data delete status : %d",statusCode); 
    //perform an action on a particular code
}
#pragma endregion
#pragma mark updateViews

#pragma endregion
@end
